from typing import List

from sam.app.base import cut_stats_export
from sam.util.dbUtil import mysql_env_config_dict, DB


class HeiMaoComplaintAnalysis(object):

    def __init__(self):
        super().__init__()
        self.db = DB(mysql_env_config_dict.get("net"), level="debug")

    def fetch_all_complaint_content(self) -> List[str]:
        query_result_list = self.db.query(
            table_name="heimao_complaint_detail"
            , column_str="complaint_content"
            , optional="tuple"
        )
        return [query_result[0] for query_result in query_result_list]

    def complaint_content_analysis(self):
        complaint_content_list = self.fetch_all_complaint_content()
        cut_stats_export(line_list=complaint_content_list, export_file_name="物业投诉分词与统计")

    def main(self):
        self.complaint_content_analysis()


def hei_mao_complaint_analysis():
    process = HeiMaoComplaintAnalysis()
    process.main()


if __name__ == "__main__":
    hei_mao_complaint_analysis()
